<template>
  <div class="tab" style="position: relative;">
    <el-menu style="height: 60px;" :default-active="$route.path" class="el-menu-demo" mode="horizontal"
      background-color="#1e6bfe" text-color="#fff" active-text-color="#ffd04b">
      <el-menu-item index="0" style=" padding: 0px; margin: 0 10px">
        <img style="width: 40px" :src="logos" alt="Element logo" /><span style="font-weight: 700;font-size: 16px;">{{
          Gsnames }}</span>
      </el-menu-item>
      <el-menu-item :index="urlArr[0].find(item => item == $route.path)"
        @click="toPeople('商品管理', '1')">商品管理</el-menu-item>
      <el-menu-item :index="urlArr[1].find(item => item == $route.path)"
        @click="toPeople('订单管理', '2')">订单管理</el-menu-item>
      <el-menu-item :index="urlArr[2].find(item => item == $route.path)"
        @click="toPeople('出库管理', '3')">出库管理</el-menu-item>
      <el-menu-item :index="urlArr[3].find(item => item == $route.path)" @click="toPeople('入库管理', '4')">
        入库管理</el-menu-item>
      <el-menu-item :index="urlArr[4].find(item => item == $route.path)"
        @click="toPeople('库存盘点', '5')">库存盘点</el-menu-item>
      <el-menu-item :index="urlArr[5].find(item => item == $route.path)"
        @click="toPeople('仓库管理', '6')">仓库管理</el-menu-item>
      <el-menu-item :index="urlArr[6].find(item => item == $route.path)"
        @click="toPeople('快递管理', '7')">快递管理</el-menu-item>
      <el-menu-item :index="urlArr[7].find(item => item == $route.path)"
        @click="toPeople('系统设置', '8')">系统设置</el-menu-item>
      <el-menu-item :index="urlArr[8].find(item => item == $route.path)"
        @click="toPeople('信息查询', '9')">信息查询</el-menu-item>
      <el-menu-item :index="urlArr[9].find(item => item == $route.path)"
        @click="toPeople('采购设置', '10')">采购设置</el-menu-item>
      <el-menu-item :index="[].find(item => item == $route.path)" @click="toPeople('数据分析', '11')">数据分析</el-menu-item>
      <el-menu-item :index="urlArr[11].find(item => item == $route.path)"
        @click="toPeople('档口管理', '12')">档口管理</el-menu-item>
      <el-menu-item :index="urlArr[12].find(item => item == $route.path)"
        @click="toPeople('仓库打印', '13')">仓库打印</el-menu-item>
      <el-menu-item :index="urlArr[13].find(item => item == $route.path)"
        @click="toConfiguration('订单配置', '14')">订单配置</el-menu-item>
      <el-menu-item :index="urlArr[14].find(item => item == $route.path)"
        @click="toPeople('日志查询', '15')">日志查询</el-menu-item>
      <el-menu-item :index="urlArr[15].find(item => item == $route.path)" v-if="haveOr('oldOrSupplycChain')"
        @click="openOld('老供应链', '16')">老供应链</el-menu-item>
      <el-menu-item style="position: absolute; right: 35px" @click="toPeoples">
        <img style="
                width: 40px;
                height: 40px;
                border-radius: 20px;
                margin-right: 15px;
              " :src="loginImg" />
        <el-dropdown>
          <span class="el-dropdown-link" style="color: #fff;">
            {{ loginName
            }}
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <!-- <el-dropdown-item @click="ToTicketSystem">工单系统</el-dropdown-item> -->
              <!-- <el-dropdown-item @click="safetyReturn">安全退出</el-dropdown-item> -->
              <el-dropdown-item @click="clearChrome">清理缓存</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </el-menu-item>
    </el-menu>
    <div class="el-dialog" v-if="dialogVisible" style="width: 350px;padding: 40px;">
      <!-- <el-dialog v-model="" width="300" :modal="false"> -->
      <span>
        老供应链账号:<el-input v-model="inputOldPlat" style="width: 140px" />
      </span>
      <!-- <template #footer> -->
      <div class="dialog-footer" style="margin-top: 20px;display: flex;justify-content: end;">
        <el-button @click="dialogVisible = false, inputOldPlat = ''">取消</el-button>
        <el-button type="primary" @click="submitOldPlat">
          绑定
        </el-button>
      </div>
      <!-- </template> -->
      <!-- </el-dialog> -->
    </div>
  </div>

  <div class="content">
    <RouterView></RouterView>
  </div>

  <div class='diaog' v-if='timerOr'>
    仔细浏览数据
    <el-table :data="outTimeList" style="width: 100%" max-height="250">
      <el-table-column prop="tid" label="父订单号" width="180" />
      <el-table-column prop="oid" label="子订单号" width="180" />
      <el-table-column prop="msg" label="状态" />
    </el-table>
    <el-button type="primary" style="margin-left: 399px;" @click="noOperationWarnUpdateBtn">确定</el-button>
  </div>
</template>

<script setup>
import axios from 'axios'
import { onBeforeMount, ref } from 'vue'
import { useRouter } from 'vue-router'
// umsThirdUserlogin
import { noOperationWarnGetDictDataListByDictTypeName, noOperationWarnUpdate, potatoadminLogin } from '@/api/index'
import { ElMessage } from 'element-plus'
import { haveOr } from '@/utils/inculd'
const router = useRouter()
// const route = useRoute()useRoute
// 头像
const logos = ref('')
const Gsnames = ref('')
onBeforeMount(() => {
  console.log('zhixingle')
  // const isAuthenticated = localStorage.getItem('system_token')
  diaogTimesBtn()
  axios.post('http://console.sc.kuaidi600.com/admin/company/read', { token: localStorage.getItem('system_token') }
  ).then(res => {
    const { data: { data } } = res
    logos.value = data.logo_url
    Gsnames.value = data.short_name
    // umsThirdUserlogin({
    //   consoleToken: isAuthenticated
    //   // consoleToken: 'b5066053c18f2c92c6507c6667906df11717750828355773e67c6ef1f7631eeac34daf75bc'
    // }).then(res => {
    //   console.log('tokenres')
    //   console.log(res)
    //   localStorage.setItem('system_token_cloudWare', res.data.data.token)
    //   ElMessage.success('已经重新登录')
    // })
  })
  loginNameimg()
})
const dialogVisible = ref(false)
// 当前登录的姓名/头像
let loginName = ref('')
let loginImg = ref('')
const loginNameimg = () => {
  loginName = localStorage.getItem('system_name')
  loginImg = JSON.parse(
    localStorage.getItem('system_data')
  ).photo_url
}
const urlArr = [
  ['/home/everyView/shopList', '/home/everyView/shopType'],
  ['/home/everyView/preSales', '/home/everyView/afterSale'],
  ['/home/everyView/marketOutOrder', '/home/everyView/retrunOrder', '/home/everyView/destroyMessageList', '/home/everyView/SignFailure'],
  ['/home/everyView/awaitAudit', '/home/everyView/awaitPurchase', '/home/everyView/purchasedButNoGo', '/home/everyView/awaitQualityTesting', '/home/everyView/inspectedAwaitDispose', '/home/everyView/awaiStock', '/home/everyView/WarehousingSuccess', '/home/everyView/ReturnToWarehouse', '/home/everyView/goReturnToWarehouse', '/home/everyView/stallStock', '/home/everyView/stallStockAwaitGet', '/home/everyView/stallStockAwaitSet', '/home/everyView/stallStockAlready'],
  ['/home/everyView/awaiCtounted', '/home/everyView/acknowledgedCtounted', '/home/everyView/shiftList', '/home/everyView/awaitAuditInentory'],
  ['/home/everyView/warehouseList', '/home/everyView/warehouseType', '/home/everyView/warehouseGoodsArea', '/home/everyView/warehouseSeat'],
  ['/home/everyView/rookieExpress'],
  ['/home/everyView/basicSetting', '/home/everyView/printSetup', '/home/everyView/userSetting', '/home/everyView/printSetup/expressSheet', '/home/everyView/printSetup/expressSheetTable'],
  ['/home/everyView/ExportInformation', '/home/everyView/templeManagement'],
  ['/home/everyView/PurchasingAccountList', '/home/everyView/PurchasingAccountPlatform', '/home/everyView/PurchasingAccountType', '/home/everyView/paymentID'],
  [],
  ['/home/everyView/stallList'],
  ['/home/everyView/afterSaleScan', '/home/everyView/prePurchasePrint'],
  ['/home/indexConfiguration'],
  ['/home/everyView/MergeLog'],
  []
]
// 点击右侧返回
const toPeople = (val, numId) => {
  console.log(urlArr[numId - 1])
  if (urlArr[numId - 1].length > 0) {
    router.push({ path: urlArr[numId - 1][0], query: { id: numId } })
  } else {
    ElMessage.error('暂无页面')
  }
}
// 清楚缓存
const clearChrome = () => {
  location.reload(true)
}
// // 退出
// const safetyReturn = () => {
//   localStorage.removeItem('system_data')
//   location.reload(true)
// }
// 点击右侧返回
const toPeoples = () => {
  window.location.href = 'http://yitaoweb.sc.kuaidi600.com/#/home/personal_center'
}

const timer = ref(null)
const timerOr = ref(false)
const outTimeList = ref([])
const diaogTimesBtn = () => {
  const datas = JSON.parse(localStorage.getItem('system_data'))
  timer.value = setInterval(() => {
    noOperationWarnGetDictDataListByDictTypeName({
      id: datas.id
    }).then(res => {
      const { data: { data } } = res
      if (data.length > 0) {
        outTimeList.value = data
        timerOr.value = true
      }
    })
  }, 700000)
}
const noOperationWarnUpdateBtn = () => {
  outTimeList.value.forEach(e => {
    noOperationWarnUpdate({ id: 0 }).then(res => {
      ElMessage.success('处理完成')
      timerOr.value = false
    })
  })
}
const toConfiguration = () => {
  router.push({ path: '/home/indexConfiguration' })
}
const inputOldPlat = ref('')
const openOld = () => {
  potatoadminLogin({ account: inputOldPlat.value }).then(res => {
    // ElMessage.success('操作成功')
    console.log('res')
    console.log(res.data.code)
    const { data: { data } } = res
    if (res.data.code === 506) {
      dialogVisible.value = true
    } else {
      dialogVisible.value = false
      document.cookie = `_token_id=${data.token}; path=/; domain=.kuaidi600.com`
      document.cookie = `username=${data.userName}; path=/; domain=.kuaidi600.com`
      document.cookie = `_authority=${JSON.stringify(data.admin.authKeys)}; path=/; domain=.kuaidi600.com`
      document.cookie = `jurisdiction='"#%9*3&"+${data.admin.gid}+"#7@#5&%2"'; path=/; domain=.kuaidi600.com`
      window.location.href = 'http://scm.kuaidi600.com/supply_chain'
    }
  })
}
const submitOldPlat = () => {
  potatoadminLogin({ account: inputOldPlat.value }).then(res => {
    ElMessage.success('操作成功')
    const { data: { data } } = res
    dialogVisible.value = false
    // 设置多个 Cookies
    document.cookie = `_token_id=${data.token}; path=/; domain=.kuaidi600.com`
    document.cookie = `username=${data.userName}; path=/; domain=.kuaidi600.com`
    document.cookie = `_authority=${JSON.stringify(data.admin.authKeys)}; path=/; domain=.kuaidi600.com`
    document.cookie = `jurisdiction='"#%9*3&"+${data.admin.gid}+"#7@#5&%2"'; path=/; domain=.kuaidi600.com`
    window.location.href = 'http://scm.kuaidi600.com/supply_chain'
  })
}
</script>

<style lang='less' scoped>
.diaog {
  width: 500px;
  // height: 254px;
  position: absolute;
  background-color: red;
  top: 307px;
  left: 810px;
  z-index: 999
}

.el-dialog {
  position: absolute;
  top: -70px;
  right: 200px;
  width: 300px;
}
</style>
